<?php
/**
 * @version		$Id: default.php 7 2011-12-22 13:48:09Z netix.mail@gmail.com $
 * @package		ALM Hoster
 * @desription	Web hosting and domain menager for resellers
 * @subpackage	Components
 * @copyright	Copyright (C) 2011 ALM Studio. All rights reserved.
 * @author		ALM Studio
 * @email		info@alm-studio.net
 * @link		http://alm-studio.net
 * @license		Commercial
 */
 
defined('_JEXEC') or die('Restricted Access');
JHtml::_('behavior.tooltip');
JHTML::_('script','system/multiselect.js',false,true);
$listOrder	= $this->escape($this->state->get('list.ordering'));
$listDirn	= $this->escape($this->state->get('list.direction'));
$config = JFactory::getConfig();
$params = JComponentHelper::getParams('com_almhoster');
$currency 	= $params->get("UseCurrency");
?>
<script>
function createInvoice(delUrl) {
	  if (confirm()) {
	    document.location = delUrl;
	  }
	}
</script>
<form action="<?php echo JRoute::_('index.php?option=com_almhoster&view=orders'); ?>" method="post" name="adminForm">
	<fieldset id="filter-bar">	
		<div class="filter-search fltlft">
			<label class="filter-search-lbl" for="filter_search"><?php echo JText::_('Filter: '); ?></label>
			<input type="text" name="filter_search" id="filter_search" value="<?php echo $this->escape($this->state->get('filter.search')); ?>" title="<?php echo JText::_('COM_ALMHOSTER_SEARCH_BY_PRODUCT_NAME'); ?>" />
			<button type="submit"><?php echo JText::_('COM_ALMHOSTER_FILTER'); ?></button>
			<button type="button" onclick="document.id('filter_search').value='';this.form.submit();"><?php echo JText::_('COM_ALMHOSTER_RESET'); ?></button>
		</div>
		<div class="filter-select fltrt">
			<select name="filter_client_id" class="inputbox" onchange="this.form.submit()">
				<option value=""><?php echo JText::_('COM_ALMHOSTER_FILTER_BY_CLIENT');?></option>
				<?php echo JHtml::_('select.options', $this->client, 'value', 'text', $this->state->get('filter.client_id'));?>
			</select>					
			<select name="filter_status_id" class="inputbox" onchange="this.form.submit()">
				<?php echo JHtml::_('select.options', array(
					JHtml::_('select.option', '', JText::_('COM_ALMHOSTER_FILTER_BY_STATUS')), 
					JHtml::_('select.option', 0, JText::_('COM_ALMHOSTER_LIST_ORDER_STATUS_0')), 
					JHtml::_('select.option', 1, JText::_('COM_ALMHOSTER_LIST_ORDER_STATUS_1')),
					JHtml::_('select.option', 2, JText::_('COM_ALMHOSTER_LIST_ORDER_STATUS_2')),
					JHtml::_('select.option', 3, JText::_('COM_ALMHOSTER_LIST_ORDER_STATUS_3'))),
							'value', 'text', $this->state->get('filter.status_id')); ?>
			</select>				
		</div>
	</fieldset>
<div class="clr"></div>
<table class="adminlist">
	<thead>
			<tr>
	<th width="5">
		<?php echo JHtml::_('grid.sort',  'Id', 'OrderId', $listDirn, $listOrder); ?>
	</th>
	<th width="10">
		<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->items); ?>);" />
	</th>
	<th width="15%">
		<?php echo JHtml::_('grid.sort',  'COM_ALMHOSTER_ORDER_CLIENT', 'OrderClient', $listDirn, $listOrder); ?>
	</th>			
	<th class="title">
		<?php echo JHtml::_('grid.sort',  'COM_ALMHOSTER_ORDER_PRODUCT', 'OrderProduct', $listDirn, $listOrder); ?>
	</th>
	<th width="7%">
		<?php echo JHtml::_('grid.sort',  'COM_ALMHOSTER_ORDER_BILLING_CYCLE', 'OrderBillingCycle', $listDirn, $listOrder); ?>
	</th>
	<th width="7%">
		<?php echo JHtml::_('grid.sort',  'COM_ALMHOSTER_ORDER_RECURRING_COST', 'OrderRecurringAmount', $listDirn, $listOrder); ?>
	</th>
	<th width="11%">
		<?php echo JHtml::_('grid.sort',  'COM_ALMHOSTER_ORDER_DOMAIN', 'OrderDomain', $listDirn, $listOrder); ?>
	</th>
	<th width="11%">
		<?php echo JHtml::_('grid.sort',  'COM_ALMHOSTER_ORDER_DOMAIN_TYPE', 'OrderDomainType', $listDirn, $listOrder); ?>
	</th>
		<th width="7%">
		<?php echo JHtml::_('grid.sort',  'COM_ALMHOSTER_ORDER_DATE', 'OrderDate', $listDirn, $listOrder); ?>
	</th>
	<th width="6%">
		<?php echo JHtml::_('grid.sort',  'COM_ALMHOSTER_ORDER_STATUS', 'OrderStatus', $listDirn, $listOrder); ?>
	</th>
	<th width="5%">
		<?php echo JText::_('COM_ALMHOSTER_ACTIONS'); ?>
	</th>
	</tr>
</thead>
<tfoot>	
	<tr>
	<td colspan="14">
		<?php echo $this->pagination->getListFooter(); ?></td>
	</tr>		
</tfoot>
<tbody>
	<?php foreach($this->items as $i => $item):
		if ($item->account == null){
			$order_acc = JText::_('COM_ALMHOSTER_NO_ACCOUNT_FOR_ORDER'); 
		}else{				
			$order_acc = JText::_(' ('.$item->account.')');
		}
?>
	<tr class="row<?php echo $i % 2; ?>">
		<td>
			<?php echo $item->OrderId; ?>
		</td>
		<td>
			<?php echo JHtml::_('grid.id', $i, $item->OrderId); ?>
		</td>
		<td>
			<?php echo $item->client; ?>
		</td>
		<td>
			<a href="<?php echo JRoute::_('index.php?option=com_almhoster&task=order.edit&OrderId=' . $item->OrderId); ?>">
				<?php echo $item->OrderProduct, $order_acc; ?>
			</a>
		</td>
		<td align="center">
			<?php echo $item->billing_cycle; ?>
		</td>
		<td align="right">
			<?php echo $item->OrderRecurringAmount, JText::_(' '), JText::_('COM_ALMHOSTER_BILLING_CURRENCY_'.$currency); ?>
		</td>
		<td align="center">
			<?php echo $item->OrderDomain; ?>
		</td>
		<td align="center">
			<?php echo JText::_('COM_ALMHOSTER_ORDER_DOMAIN_TYPE_'.$item->OrderDomainType); ?>
		</td>
		<td align="center">
			<?php echo $item->OrderDate; ?>
		</td>
		<?php
					if ($item->OrderStatus == 0) { ?>
			<td align="center" style= "background-color: #faf29f">
				<strong>
					<?php echo JText::_('COM_ALMHOSTER_LIST_ORDER_STATUS_'.$item->OrderStatus); ?>
				</strong>
			</td>
				<?php
					} if ($item->OrderStatus == 1) { ?>
			<td align="center" style= "background-color: #a8db99">
				<strong>
				<?php echo JText::_('COM_ALMHOSTER_LIST_ORDER_STATUS_'.$item->OrderStatus); ?>
				</strong>
			</td>
			<?php
				} if ($item->OrderStatus == 2) { ?>
			<td align="center" style= "background-color: #ff6666">
				<strong>
				<?php echo JText::_('COM_ALMHOSTER_LIST_ORDER_STATUS_'.$item->OrderStatus); ?>
				</strong>
			</td>				
				<?php
				}	if ($item->OrderStatus == 3) { ?>
			<td align="center" style= "background-color: #c9ddde">
				<strong>
				<?php echo JText::_('COM_ALMHOSTER_LIST_ORDER_STATUS_'.$item->OrderStatus); ?>
				</strong>
			</td>
				<?php
					} ?>
			<td align="center">	
				<a type="image"  href="<?php echo JRoute::_('index.php?option=com_almhoster&task=orders.createInvoice&OrderId=' . $item->OrderId); ?>" 
				onclick="return confirm('<?php echo JText::_('COM_ALMHOSTER_CONFIRM_INVOICE_CREATION').$item->OrderId.' - '.$item->OrderProduct, $order_acc;  ?>')"">
					<img src="../media/com_almhoster/images/invoice.png" title="<?php echo JText::_('COM_ALMHOSTER_CREATE_INVOICE'); ?>"> 
				</a>
				<a type="image" href="<?php echo JRoute::_('index.php?option=com_almhoster&task=orders.cancelOrder&OrderId=' . $item->OrderId); ?>" 
					onclick="return confirm('<?php echo JText::_('COM_ALMHOSTER_CONFIRM_ORDER_CANCELATION').$item->OrderId.' - '.$item->OrderProduct.'?'; ?>')"">
					<img src="../media/com_almhoster/images/cancel.png" title="<?php echo JText::_('COM_ALMHOSTER_CANCEL_ORDER'); ?>"> 
				</a>	
				<?php if ($item->OrderAccount == 0){				
					}else{		
						if ($item->acc_status == 0){ ?>
						<a type="image" href="<?php echo JRoute::_('index.php?option=com_almhoster&task=orders.suspendAccount&OrderId=' . $item->OrderId); ?>" 
							onclick="return confirm('<?php echo JText::_('COM_ALMHOSTER_CONFIRM_ACCOUNT_SUSPENDATION'), $item->account, JText::_('COM_ALMHOSTER_PRODUCT_SERVICE'); ?>')"">
						<img src="../media/com_almhoster/images/stop.png" title="<?php echo JText::_('COM_ALMHOSTER_SUSPEND_ACCOUNT'); ?>"> 
						</a>
						<?php }elseif ($item->acc_status == 1){ ?>
						<a type="image" href="<?php echo JRoute::_('index.php?option=com_almhoster&task=orders.unsuspendAccount&OrderId=' . $item->OrderId); ?>" 
							onclick="return confirm('<?php echo JText::_('COM_ALMHOSTER_CONFIRM_ACCOUNT_UNSUSPENDATION'), $item->account, JText::_('COM_ALMHOSTER_PRODUCT_SERVICE'); ?>')"">
						<img src="../media/com_almhoster/images/start.png" title="<?php echo JText::_('COM_ALMHOSTER_UNSUSPEND_ACCOUNT'); ?>"> 
						</a>
				<?php }
				}?>
			</td>						
		</tr>	
	<?php endforeach; ?>
</tbody>
	</table>
	<div>
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" />
		<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" />
		<?php echo JHtml::_('form.token'); ?>
	</div>
</form>
